from enum import Enum
from typing import NamedTuple, Any

import skills
from ui import CardUI


class CardTypes(Enum):
    Environment = 1
    Basic = 2
    Magic = 3
    Equipment = 4
    Disposal = 5


class CardInfo(NamedTuple):
    name: str
    id: str
    type: CardTypes
    skill: Any
    energy: int
    CD: int
    usable: int
    num: int


cards = [CardInfo("走位1", "move1", CardTypes.Basic, skills.move1, 0, 0, 99999999, 42)]


class Card(CardUI):
    def __init__(self, card_info, *keys, index):
        super().__init__(*keys)
        self.index = index
        self.name, self.id, self.type, self.skill, self.energy, self.cd, self.usable, _ = card_info

    def is_equip(self):
        return self.type == CardTypes.Equipment

    def is_magic(self):
        return self.type == CardTypes.Magic

    def is_disposal(self):
        return self.type == CardTypes.Disposal

    def is_environment(self):
        return self.type == CardTypes.Environment


def create_card_pile():
    cards_index = {}
    i = 0
    card_pile = []
    for card_info in cards:
        for _ in range(card_info.num):
            card = Card(card_info, index=i)
            cards_index[i] = card
            i += 1
            card_pile.append(card)
    return card_pile, cards_index
